package utils

import pb "fastdp-ops/proto/exec"

// 创建基础响应对象
func baseResponse(req *pb.Execrequest) *pb.ExecResponse {
	return &pb.ExecResponse{
		MachineId: req.MachineId,
		TaskId:    req.TaskId,
		Error: &pb.ErrorDetail{
			Code:    0, // 默认为0，表示无错误
			Message: "",
			Trace:   "",
		},
	}
}

func ErrorResponse(req *pb.Execrequest, code int32, message string) *pb.ExecResponse {
	resp := baseResponse(req)
	resp.Success = false // 标记执行失败
	resp.Error = &pb.ErrorDetail{
		Code:    code,
		Message: message,
		Trace:   "", // 调试时传入堆栈，生产可传空
	}
	return resp
}

// 创建成功响应
func SuccessResponse(req *pb.Execrequest, stdout, details string) *pb.ExecResponse {
	resp := baseResponse(req)
	resp.Success = true
	resp.Stdout = stdout
	resp.Change = true
	resp.ChangedDetails = details
	return resp
}

// 新增：无变更的成功响应（change=false）
func SuccessResponseWithNoChange(req *pb.Execrequest, stdout, details string) *pb.ExecResponse {
	resp := baseResponse(req)
	resp.Success = true
	resp.Stdout = stdout
	resp.Change = false // 关键：无变更
	resp.ChangedDetails = details
	return resp
}
